﻿///////////////////////////////////////////////////////////////////////////////////////////////
// System.Text.Parsing - © 2011 Sebastien Pellizzari
// Released under the MIT License (http://www.opensource.org/licenses/mit-license.php)
///////////////////////////////////////////////////////////////////////////////////////////////
using System.Collections;
using System.Collections.Generic;

namespace System.Text.Parsing
{
    /// <summary>Represents a collection of parser definitions.</summary>
    public sealed class GrammarParserCollection : IEnumerable<GrammarParser>
    {
        private readonly List<GrammarParser> _list;

        //-----------------------------------------------------------------------
        //     Properties
        //-----------------------------------------------------------------------

        /// <summary>Gets the number of elements in the collection.</summary>
        public int Count { get { return _list.Count; } }

        /// <summary>Gets the parser definition object at specified index.</summary>
        /// <param name="index">The zero-based index of desired element.</param>
        public GrammarParser this[int index] { get { return _list[index]; } }

        //-----------------------------------------------------------------------
        //     Constructors
        //-----------------------------------------------------------------------

        /// <summary>Initializes an instance of the <see cref="GrammarParserCollection"/> class.</summary>
        public GrammarParserCollection()
        {
            _list = new List<GrammarParser>();
        }

        //-----------------------------------------------------------------------
        //     Methods
        //-----------------------------------------------------------------------

        /// <summary>Adds an element to the collection.</summary>
        public void Add(GrammarParser parser)
        {
            if (parser == null) throw new ArgumentNullException("parser");
            _list.Add(parser);
        }

        /// <summary>Returns an object that iterates through the collection.</summary>
        /// <returns>An object that implements the <see cref="IEnumerator{GrammarParser}"/> interface.</returns>
        public IEnumerator<GrammarParser> GetEnumerator() { return _list.GetEnumerator(); }

        //-----------------------------------------------------------------------
        //     Non Public
        //-----------------------------------------------------------------------

        // GetEnumerator method.
        IEnumerator IEnumerable.GetEnumerator() { return _list.GetEnumerator(); }
    }
}
